//
//  TETBXMLViewController.m
//  TintExample
//
//  Created by Kevin Wu on 3/8/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TETBXMLViewController.h"

@implementation TETBXMLViewController



#pragma mark - UIViewController

- (void)loadView {
    [super loadView];
    
    [self addButtonWithTitle:@"Parse test1.xml" selector:@selector(parse1:)];
    [self addButtonWithTitle:@"Parse test2.xml" selector:@selector(parse2:)];
    [self addButtonWithTitle:@"Parse test3.xml" selector:@selector(parse3:)];
    [self addButtonWithTitle:@"Parse dirty" selector:@selector(parseDirty:)];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
}


- (void)parse1:(id)sender {
    TBXML *tbxml = [[TBXML alloc] initWithXMLFile:@"test1.xml"];
    
    TBXMLElement *element = NULL;
    if (tbxml.rootXMLElement) {
        element = [TBXML firstChildOfElement:tbxml.rootXMLElement];
    }
    
    while (element) {
        NSLog(@"%@", [TBXML elementName:element]);
        element = [TBXML nextSiblingOfElement:element];
    }
    
    TTRelease(tbxml);
}

- (void)parse2:(id)sender {
    TBXML *tbxml = [[TBXML alloc] initWithXMLFile:@"test2.xml"];
    
    TBXMLElement *element = NULL;
    if (tbxml.rootXMLElement) {
        element = [TBXML firstChildOfElement:tbxml.rootXMLElement];
    }
    
    while (element) {
        NSLog(@"%@", [TBXML elementName:element]);
        element = [TBXML nextSiblingOfElement:element];
    }
    
    TTRelease(tbxml);
}

- (void)parse3:(id)sender {
    TBXML *tbxml = [[TBXML alloc] initWithXMLFile:@"test3.xml"];
    
    TBXMLElement *paragraph = NULL;
    if (tbxml.rootXMLElement) {
        paragraph = [TBXML firstChildOfElement:tbxml.rootXMLElement];
    }
    
    TBXMLElement *element = NULL;
    if (paragraph) {
        element = [TBXML firstChildOfElement:paragraph];
    }
    
    NSLog(@"%@", [TBXML textForElement:paragraph]);
    
    while (element) {
        NSLog(@"%@", [TBXML elementName:element]);
        element = [TBXML nextSiblingOfElement:element];
    }
    
    TTRelease(tbxml);
}

- (void)parseDirty:(id)sender {
    TBXML *tbxml = [[TBXML alloc] initWithXMLString:@"alskdjowee asdk,sdfjasdf"];
    
    TBXMLElement *element = NULL;
    if (tbxml.rootXMLElement) {
        element = [TBXML firstChildOfElement:tbxml.rootXMLElement];
    }
    
    while (element) {
        NSLog(@"%@", [TBXML elementName:element]);
        element = [TBXML nextSiblingOfElement:element];
    }
    
    TTRelease(tbxml);
}

@end
